<template>
  <div class="app-container">
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <div class="left" v-for="(item,index) in form_col" :key="index">
          <el-form-item :label="item.title" :prop="item.prop">
            <el-date-picker v-if="item.type === 'date'" v-model="form[item.prop]" type="date" size="mini" :placeholder="item.placeholder" value-format="yyyy-MM-dd" style="width:100%">
            </el-date-picker>
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel" size="mini">取 消</el-button>
        <el-button type="primary" @click="submitForm" size="mini">确认启动</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { updateProjects, getProjects } from "@/api/business/project/projects";
export default {
  data() {
    return {
      title: '启动',
      open: false,
      form: {
        startDate: null,
        pStatus: '1'
      },
      form_col: [{ title: '实际启动日期', prop: 'startDate', type: 'date', placeholder: '请选择实际启动日期', show: true, disabled: false }],
      rules: {}
    }
  },
  methods: {
    init(row) {
      this.open = true;
      this.rest()
      this.getProjectsDetail(row)
    },
    /** 获取详情 */
    getProjectsDetail(row) {
      const id = row.id
      getProjects(id).then(response => {
        this.form = response.data;
        this.form.startDate = null
      });
    },
    rest() {
      this.form = {
        startDate: null,
        pStatus: '1'
      }
      this.resetForm("form");
    },
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.pStatus = '1'
          updateProjects(this.form).then(response => {
            this.$modal.msgSuccess("启动成功");
            this.open = false;
            this.$parent.getList()
          });

        }
      });
    },
    cancel() {
      this.open = false;
      this.rest()
    }
  }
}
</script>

<style lang="scss" scoped>
</style>